/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package g5.form;

import g5.fw.HBox;
import g5.fw.IField;
import g5.fw.ISection;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author Hue
 */
public class Section implements ISection {
    private String pk;
    private String code;
    private String name;
    private String type;
    private ArrayList<HBox<IField>> hBoxes;

    public void setPK(String value) {
        this.pk = value;
    }

    @Override
    public String getPK() {
        return this.pk;
    }
    
    public void setCode(String value) {
        this.code = value;
    }

    @Override
    public String getCode() {
        return this.code;
    }
    
    public void setName(String value) {
        this.name = value;
    }

    @Override
    public String getName() {
        return this.name;
    }

    public void setType(String value) {
        this.type = value;
    }

    @Override
    public String getType() {
        return this.type;
    }

    @Override
    public ArrayList<HBox<IField>> getHBoxes() {
        if(hBoxes == null) {
            hBoxes = new ArrayList();
        }
        return hBoxes;
    }

    @Override
    public JSONObject toJSON() throws JSONException {
        JSONObject jsObj = new JSONObject();
        jsObj.put("pk", getPK());
        jsObj.put("code", getCode());
        jsObj.put("name", getName());
        jsObj.put("type", getType());
        
        JSONArray jsBoxes = new JSONArray();
        for(HBox box : hBoxes) {
            jsBoxes.put(box.toJSON());
        }
        jsObj.put("hBoxes", jsBoxes);
        
        return jsObj;
    }
}
